﻿<?php
function cTabela()
{
	require("conexao.php");	
	echo "<table id='tbcontas' border='1'>" ;
	echo "<thead>" ;
	echo "<tr class='yellow' >" ;	
	echo "<th>Data Vencimento</th>" ;
	echo "<th>Nº Conta</th>" ;	
	echo "<th>Observacao</th>" ;
	echo "<th>Valor</th>" ;	
	echo "<th>Situação</th>" ;
	echo "<th>Comprovante</th>" ;	
	echo "</tr>" ;
	echo "</thead>" ;
	echo "<tbody>" ;
	
	$iduser = $_SESSION["user"]["ID"];
	$sql = "select c.*, t.* from contaspagarreceber c, conta t where c.idconta = t.idconta and t.idusuario = $iduser order by c.data_vcto";
	$result = mysql_query($sql);
	
   while ($v = mysql_fetch_array($result))
   {

	$data2 = strtotime($v["data_vcto"]);
	echo "<tr id='" . $v["idcontas"] . "'>" ;
	echo "<td class='read_only'>" . date("d/m/Y", $data2) . "</td>" ;
	echo "<td class='read_only'>" . $v["numero_conta"] ."</td>" ;	
	echo "<td>" . $v["descricao"]. "</td>" ;
	echo "<td>" . $v["valor"] ."</td>" ;	
	echo "<td class='read_only'>" . $v["situacao"] ."</td>" ;
	
	$id = $v["idcontas"];
	$sql2 = "select * from comprovantes where idcontas = $id ";
	$result2 = mysql_query($sql2);
	$v2 = mysql_fetch_array($result2);
	
	if($v2["comprovante"] != ""){
	echo "<td class='read_only'>" . "<div class='gallery_in'><ul><li><a href='uploads/" . $v2["comprovante"] . "' ><img src='imagens/comprovante.gif' width='15' height='20' /></a></li></ul></div>" . "</td>" ;
	
	/*<div class="gallery_in">
                <ul>
                    <li>
                        <a href="images/1.jpg" title="" ><img src="images/1_s.jpg" alt="demo" width="200" height="139" /></a>
                    </li>
					</ul>
					</div>
	*/
	}
	else{
	echo "<td class='read_only'>" . "Não" . "</td>" ;
	}
	echo "</tr>" ;
	
   }

	echo "</tbody>" ;
    echo "</table>" ;	
}

function inserir($array)
{
	require("conexao.php");	
	$sql = "";
	foreach ($array as $v)
	{
	$sql = "INSERT INTO contaspagarreceber(idclassificacao, idconta, data_vcto, data_pgto, valor, descricao, situacao, tipo) 
	Values('" . $v['idclassificacao'] . "', '" . $v['idconta'] . "', '" . $v['data_vcto'] . "', '" . $v['data_pgto'] . "', '" . $v['valor'] . "', '" . $v['descricao'] . "', '" . $v['situacao'] . "', '" . $v['tipo'] . "')" ;
	

	
	if (!mysql_query($sql,$con))
  	  {
  		die('Error: ' . mysql_error());
  	  }	
	}
	mysql_close($con);
}

?>